<?php
/**
 * @copyright: ©2024 永州微聚 商网络科技有限公司
 * @link: https://www.weijuYunke.com
 */

namespace app\mobile\controller;


use AlibabaCloud\SDK\ICE\V20201109\Models\GetMediaInfoRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetMediaProducingJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetSmartHandleJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\RegisterMediaInfoRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitMediaProducingJobRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use app\admin\model\ClipBackgroundImg;
use app\admin\model\ClipBackgroundMusic;
use app\admin\model\ClipFlowerText;
use app\admin\model\ClipFont;
use app\admin\model\ClipMaterial;
use app\admin\model\ClipMission;
use app\admin\model\ClipModel;
use app\admin\model\ClipProject;
use app\admin\model\ClipResource;
use app\admin\model\ClipSoundContent;
use app\admin\model\ClipTask;
use app\admin\model\ClipTextAdmissionSpecial;
use app\admin\model\ClipTitle;
use app\admin\model\ClipVideo;
use app\admin\model\FigureCompositeAvatar;
use app\admin\model\FigureCompositeSound;
use app\admin\model\FigureUser;
use app\admin\model\FigureVideo;
use app\admin\model\ScanTask;
use app\admin\model\ScanTaskVideo;
use app\admin\model\template\Task;
use app\BaseController;
use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitASRJobRequest;
use app\common\service\ApiService;
use OSS\OssClient;
use think\App;
use think\Exception;


/**
 * 合伙人
 *
 * @author Administrator
 *
 */
class Clip extends BaseController
{
    protected $fontData = [
        ['value' => 'FZFangSong-Z02S', 'name' => '方正仿宋简体', 'create_time' => '1734745663'],
        ['value' => 'FZHei-B01S', 'name' => '方正黑体简体', 'create_time' => '1734745663'],
        ['value' => 'FZKai-Z03S', 'name' => '方正楷体简体', 'create_time' => '1734745663'],
        ['value' => 'FZShuSong-Z01S', 'name' => '方正书宋简体', 'create_time' => '1734745663'],
        ['value' => 'SimSun', 'name' => '宋体', 'create_time' => '1734745663'],
        ['value' => 'WenQuanYi MicroHei', 'name' => '文泉驿微米黑', 'create_time' => '1734745663'],
        ['value' => 'WenQuanYi Zen Hei Mono', 'name' => '文泉驿等宽正黑', 'create_time' => '1734745663'],
        ['value' => 'WenQuanYi Zen Hei Sharp', 'name' => '文泉驿点阵正黑', 'create_time' => '1734745663'],
        ['value' => 'Microsoft YaHei', 'name' => '微软雅黑', 'create_time' => '1734745663'],
        ['value' => 'Yuanti SC', 'name' => '圆体-简常规体', 'create_time' => '1734745663'],
        ['value' => 'Alibaba PuHuiTi', 'name' => '阿里巴巴普惠体', 'create_time' => '1734745663'],
        ['value' => 'KaiTi', 'name' => '楷体', 'create_time' => '1734745663'],
        ['value' => 'SiYuan Heiti', 'name' => '思源黑体', 'create_time' => '1734745663'],
        ['value' => 'SiYuan SimSun', 'name' => '思源宋体', 'create_time' => '1734745663'],

    ];


    protected $position  =[
        /*[
            'X'=>0,
            'Y'=> 0.24,
            'Alignment'  => 'Left'

        ],
        [
            'Alignment'  => 'Right',
            'X'=>0.95,
            'Y'=> 0.24
        ],
        [
            'Alignment'  => 'Center',
            'X'=>0.475,
            'Y'=> 0.24,

        ],
        [
            'Alignment'  => 'CenterCenter',
            'X'=>0,
            'Y'=> 0,
        ],*/
        [
            'Alignment'  => 'Left',
            'X'=>0.02,
            'Y'=> 0.689,
        ],
      /*  [
            'Alignment'  => 'Center',
            'X'=>0.495,
            'Y'=> 0.689,
        ],*/
        [
            'Alignment'  => 'Right',
            'X'=>0.95,
            'Y'=> 0.689,
        ],
    ];
    protected $keywordColour  =[
        'FF0000',
        '00FF00',
        'FFBE00',
        'FF6600',
        '48A1FF',
        'FF7F50',
        'FFFFFF',
        '51FA4C',
        'FF3300',
        '0000FF',
        '5C00FF',
    ];
    protected $AaiMotionInEffect  =[
       // 'wave_in',
        'slingshot_in',
        'zoomout_in',
        'zoomin_out',
        'zoomslightout_out',
        'fade_in',
        'growth_in',
        'blur_in',
    ];
    /**
     * @return \think\response\Json 字体列表
     */
    public function fontList()
    {
        $fontModel = new ClipFont();
        $data = $fontModel->select()->toArray();
        if (empty($data)) {
            $fontModel->insertAll($this->fontData);
            $data = $fontModel->select()->toArray();
        }
        $count = $fontModel->count();
        return result(0, 'success', array(
            'list' => $data,
            'total' => $count,

        ));
    }

    /**
     * @return \think\response\Json 花字列表
     */
    public function flowerTextList()
    {
        $fontModel = new ClipFlowerText();
        $data = $fontModel->select()->toArray();
        $count = $fontModel->count();
        return result(0, 'success', array(
            'list' => $data,
            'total' => $count,

        ));
    }

    /**
     * @return \think\response\Json  文字特效oa
     */
    public function textSpecial()
    {
        $fontModel = new ClipTextAdmissionSpecial();
        $data = $fontModel->select()->toArray();
        $count = $fontModel->count();
        return result(0, 'success', array(
            'list' => $data,
            'total' => $count,

        ));
    }


    /**
     *  音乐分类
     */
    public function musicCollects()
    {

        $apiService = new ApiService();
        $result = $apiService->musicCollects();
        if ($result['code'] == 1) {
            return result(0, 'success', $result['data']);
        }
        return result(-1, $result['msg']);

    }

    /**
     *  音乐列表
     */
    public function musicList()
    {
        $id = input('mcid');
        $apiService = new ApiService();
        $result = $apiService->getMusic($id);
        if ($result['code'] == 1) {
            return result(0, 'success', $result['data']);
        }
        return result(-1, $result['msg']);


    }

    public function modelList()
    {
        $modelModel = new ClipModel();
        $data = $modelModel->select()->toArray();
        foreach ($data as $key => $value) {
            $data[$key]['url'] = 'https://' . $_SERVER['HTTP_HOST'] . $value['url'];
            $data[$key]['img_url'] = 'https://' . $_SERVER['HTTP_HOST'] . $value['img_url'];

        }
        $count = $modelModel->count();
        return result(0, 'success', array(
            'list' => $data,
            'total' => $count,

        ));
    }

    public function backgroundImgList()
    {
        $modelModel = new ClipBackgroundImg();
        $data = $modelModel->select()->toArray();
        foreach ($data as $key => $value) {
            $data[$key]['url'] = 'https://' . $_SERVER['HTTP_HOST'] . $value['url'];
        }
        $count = $modelModel->count();
        return result(0, 'success', array(
            'list' => $data,
            'total' => $count,

        ));
    }

    /**
     *  添加剪辑任务
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */

    public function clipTask()
    {
        $request = $this->request;
        $param = $request->param();

        if (!isset($param['video_id']) && empty($param['video_id'])) {
            return result(-1, '请选择剪辑视频');
        }
        /*  foreach ($param['video_id'] as $videoValue) {
              $content = json_encode(  $videoValue['content']);
              $ClipSoundContentModel = new ClipSoundContent();
              $ClipSoundContentModel->where(['id' => 1])->update(['content' => $content]);
              var_dump($content);exit;

          }*/
        //  $video_id = explode(',', $param['video_id']);

        $tally = sysconfig('tally', 'clip_price');
        $count = count($param['video_id']);
        $videoModel = new  FigureVideo();
        foreach ($param['video_id'] as $value){
            $videoInfo = $videoModel->where('id', '=', $value['id'])->find();
            if (empty($videoInfo)){
                return result(-1,'请选择正确的视频' );
            }
            if (strpos($videoInfo['result'], 'aliyuncs.com') === false) {
                return result(-1, $videoInfo['name'] . '视频链接有误，请重新选择');
            }
        }


        if (isset($param['multiple']) && $param['multiple'] > 0) {

        } else {
            $param['multiple'] = 1;
        }
        if (isset($param['multiple']) && $param['multiple'] > 0) {
            $count = $param['multiple'] * $count;
        }
        $money = $count * $tally;
        $user = FigureUser::where('id', $param['uid'])->find();
        if ($user['balance'] < $money) {
            return result(-2, '点数不足，请充值');
        }

        $data = [
            'log_no' => getPayNo('CP'),
            'uid' => $param['uid'],
            'title_show_time' => $param['title_show_time'],
            'status' => 0,
            'multiple' => $param['multiple'],
            'create_time' => time(),
            'model_id' => isset($param['model_id']) ? $param['model_id'] : 1,
            'background_img_id' => isset($param['background_img_id']) ? $param['background_img_id'] : 0,
        ];


        try {
            $clipMission = new ClipMission();
            $clipMission->startTrans();
            $missionId = $clipMission->insertGetId($data);
            // 标题
            if (isset($param['title']) && $param['title']) {
                $titleArray = explode(',', $param['title']);
                $titleData = [];
                if ($titleArray) {
                    foreach ($titleArray as $titleValue) {
                        $titleData[] =
                            [
                                'title' => $titleValue,
                                'mission_id' => $missionId,
                                'create_time' => time(),
                            ];
                    }
                }

                $ClipTitleModel = new ClipTitle();
                if ($titleData) {
                    $ClipTitleModel->insertAll($titleData);
                }
            }

            //背景音乐
            if (isset($param['background_music']) && $param['background_music']) {
               // $backgroundMusicArray = explode(',', $param['background_music']);
                $backgroundMusicData = [];

                foreach ($param['background_music'] as $backgroundMusicValue) {
                    $backgroundMusicData[] =
                        [
                            'primary_url' => $backgroundMusicValue['url'],
                            'mission_id' => $missionId,
                            'volume' =>  bcdiv($backgroundMusicValue['volume'],10,1),
                            'create_time' => time(),
                        ];
                }
                $ClipBackgroundMusicModel = new ClipBackgroundMusic();
                if ($backgroundMusicData) {
                    $ClipBackgroundMusicModel->insertAll($backgroundMusicData);
                }
            }

            $videoData = [];
            foreach ($param['video_id'] as $videoValue) {

                $videoData[] =
                    [
                        'video_id' => $videoValue['id'],
                        'mission_id' => $missionId,
                        'create_time' => time(),
                        'keynote_content'=>isset($videoValue['keynote_content']  ) && $videoValue['keynote_content'] ?json_encode( $videoValue['keynote_content']):'',
                        'content'=> isset( $videoValue['finalContent'] ) && $videoValue['finalContent']? json_encode($videoValue['finalContent']):'',
                    ];


            }
            $clipVideoModel = new ClipVideo();
            if ($videoData) {
                $clipVideoModel->insertAll($videoData);
            }

            if (isset($param['material_url']) && $param['material_url']) {
                $materialUrlArray = explode(',', $param['material_url']);
                $materialUrlData = [];
                foreach ($materialUrlArray as $materialUrlValue) {
                    $materialUrlData[] =
                        [
                            'material_url' => $materialUrlValue,
                            'mission_id' => $missionId,
                            'create_time' => time(),
                        ];
                }
                $ClipMaterialModel = new ClipMaterial();
                if ($materialUrlData) {
                    $ClipMaterialModel->insertAll($materialUrlData);
                }
            }

            $clipMission->commit();
        } catch (\Exception $exception) {
            $clipMission->rollback();
            return result(-1, $exception->getMessage());

        }


        user_balance_used($param['uid'], $data['log_no'], 2, 11, $count);
        return result(0, '添加成功', $missionId);
        /*     $data = [
             'title' => $param['title'],
             'video_id' => $param['video_id'],
             'captions_swich' => $param['captions_swich'],
             'background_music' => $param['background_music'],
             'create_time' => time(),
             'update_time' => time(),
             'uid' => $param['uid'],
             'log_no' => getPayNo('CP'),
         ];$video_id = explode(',', $param['video_id']);
         $tally = sysconfig('tally', 'clip_price');
         $money = count($video_id) * $tally;
         $user = FigureUser::where('id', $param['uid'])->find();
         if ($user['balance'] < $money) {
             return result(-2, '点数不足，请充值');
         }
         $data = [
             'title' => $param['title'],
             'video_id' => $param['video_id'],
             'captions_swich' => $param['captions_swich'],
             'background_music' => $param['background_music'],
             'create_time' => time(),
             'update_time' => time(),
             'uid' => $param['uid'],
             'log_no' => getPayNo('CP'),
         ];

         if ($param['title']) {
             $data['title_font'] = $param['title_font'] ? $param['title_font'] : 'FZFangSong-Z02S';
             $data['title_font_id'] = $param['title_font_id'] ? $param['title_font_id'] : 1;
             $data['title_colour'] = $param['title_colour'] ? $param['title_colour'] : '#ffffff';
             $data['title_back_colour'] = $param['title_back_colour'] ? $param['title_back_colour'] : '#000000';
             $data['title_text_size'] = $param['title_text_size'] ? $param['title_text_size'] : 50;
             $data['title_text_admission_special_id'] = $param['title_text_admission_special_id'];
             $data['title_text_admission_special'] = $param['title_text_admission_special'];
         }
         if ($param['deputy_title']) {
             $data['deputy_title'] = $param['deputy_title'];
             $data['deputy_title_font'] = $param['deputy_title_font'] ? $param['deputy_title_font'] : 'FZFangSong-Z02S';
             $data['deputy_title_font_id'] = $param['deputy_title_font_id'] ? $param['deputy_title_font_id'] : 1;
             $data['deputy_title_colour'] = $param['deputy_title_colour'];
             $data['deputy_title_back_colour'] = $param['deputy_title_back_colour'] ? $param['deputy_title_back_colour'] : '#000000';
             $data['deputy_text_size'] = $param['deputy_text_size'] ? $param['deputy_text_size'] : 40;
             $data['deputy_title_text_admission_special'] = $param['deputy_title_text_admission_special'];
             $data['deputy_title_text_admission_special_id'] = $param['deputy_title_text_admission_special_id'];
         }

         if ($param['captions_swich'] == 1) {
             $data['captions_text_admission_special'] = $param['captions_text_admission_special'];
             $data['captions_text_admission_special_id'] = $param['captions_text_admission_special_id'];
             $data['captions_text_size'] = $param['captions_text_size'] ? $param['captions_text_size'] : 35;
             $data['captions_font'] = $param['captions_font'] ? $param['captions_font'] : 'FZFangSong-Z02S';
             $data['captions_font_id'] = $param['captions_font_id'] ? $param['captions_font_id'] : '1';
             $data['captions_back_colour'] = $param['captions_back_colour'] ? $param['captions_back_colour'] : '#000000';;
             $data['captions_colour'] = $param['captions_colour'] ? $param['captions_colour'] : '#ffffff';

         }
         if ($param['captions_flower_text_id']) {
             $clipFlowerTextModel = new ClipFlowerText();
             $clipFlowerTextInfo = $clipFlowerTextModel->where(['id' => $param['captions_flower_text_id']])->find();
             $clipFlowerTextInfoData = [
                 'effect_color_style' => $clipFlowerTextInfo['effect_color_style'],
                 'outline_colour' => $clipFlowerTextInfo['outline_colour'],
                 'back_colour' => $clipFlowerTextInfo['back_colour'],
             ];
             $data['captions_flower_text_id'] = $param['captions_flower_text_id'];
             $data['captions_flower_text'] = json_encode($clipFlowerTextInfoData);
         }
         // 35 //45 // 55  字幕
         //50 //60 //70   // 标题
         //40 // 50 //60  // 副标题
         if ($param['title_time'] == 1) {
             $data['title_time'] = 3;
         } else {
             $data['title_time'] = 0;
         }
         if ($param['title_time'] == 1) {
             $data['deputy_title_time'] = 3;
         } else {
             $data['deputy_title_time'] = 0;
         }
         $clipTaskModel = new ClipTask();
         $videoIdList = explode(',', $param['video_id']);

         $tally = sysconfig('tally', 'clip_price');
         $data['unit_price'] = $tally;
         $data['total_price'] = bcmul($tally, count($videoIdList), 2);

         user_balance_used($param['uid'], $data['log_no'], 2, 11, count($videoIdList));
         $clipTaskModel->insert($data);

         return result(0, '添加成功', $clipTaskModel->getLastInsID());*/

    }


    /**
     *
     *  提交视频媒资，提交音频转文字任务
     *   * @throws \OSS\Core\OssException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function clipVideo()
    {

        ini_set("memory_limit", "1024M");
        ini_set('max_execution_time', 1000);
        $clipMissionModel = new ClipMission();
        $clipList = $clipMissionModel->where(['status' => 0])->select();
        $clipVideoModel = new ClipVideo();
        $videoModel = new FigureVideo();
        $config = new \Darabonba\OpenApi\Models\Config([
            // 您的AccessKey ID
            "accessKeyId" => sysconfig('upload', 'alioss_access_key_id'),
            // 您的AccessKey Secret
            "accessKeySecret" => sysconfig('upload', 'alioss_access_key_secret'),
            'endpoint' => sysconfig('upload', 'alioss_clip_endpoint'),
        ]);
        $client = new ICE($config);
        $clipProjectData = [];

        foreach ($clipList as $value) {
            try {

                //  $clipMissionModel->startTrans();
                $clipProjectData = [];
                $clipMissionModel->where(['id' => $value['id']])->update(['status' => 8]);
                $videoList = $clipVideoModel->where(['mission_id' => $value['id']])->select();
                $videoCount = count($videoList);
                $background_img_media_id = '';
                $background_img_url = '';
                $backgroundImgModel = new ClipBackgroundImg();
                $clipProjectModel = new  ClipProject();
                if ($value['background_img_id']) {
                    $backgroundImgInfo = $backgroundImgModel->where(['id' => $value['background_img_id']])->find();
                    if ($backgroundImgInfo) {
                        if ($backgroundImgInfo['oss_url']) {
                            try { //  查询是否注册媒资
                                $getMediaBackgroundImgRequest = new GetMediaInfoRequest([
                                    "inputURL" => $backgroundImgInfo['oss_url']
                                ]);
                                $runtime = new RuntimeOptions([]);
                                $getMediaInfo = $client->getMediaInfoWithOptions($getMediaBackgroundImgRequest, $runtime);

                                $background_img_media_id = $getMediaInfo->body->mediaInfo->mediaId;;
                                $background_img_url = $backgroundImgInfo['oss_url'];
                            } catch (\Exception $exception) {

                                try { // 注册媒资
                                    $registerbackgroundImgRequest = new RegisterMediaInfoRequest([
                                        "inputURL" => $backgroundImgInfo['oss_url'], 'MediaType' => 'image'
                                    ]);
                                    $runtime = new RuntimeOptions([]);
                                    $registerbackgroundImgMediaInfoResult = $client->registerMediaInfoWithOptions($registerbackgroundImgRequest, $runtime);
                                    if ($registerbackgroundImgMediaInfoResult->body->mediaId) {
                                        $background_img_media_id = $registerbackgroundImgMediaInfoResult->body->mediaId;
                                        $background_img_url = $backgroundImgInfo['oss_url'];
                                        $backgroundImgModel->where(['id' => $value['background_img_id']])->update([
                                            'oss_url' => $backgroundImgInfo['oss_url'],
                                        ]);
                                    }
                                } catch (\Exception $exception) {
                                    $clipTaskInfo = $clipMissionModel->where(['id' => $value['id']])->find();
                                    if ($clipTaskInfo['error_msg']) {
                                        $error_msg = $clipTaskInfo['error_msg'] . '---:' . $exception->getMessage();
                                    } else {
                                        $error_msg = $exception->getMessage();
                                    }
                                    $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);
                                    user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);

                                    continue;
                                }
                            }
                        } else {
                            $ossClient = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                                sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                                sysconfig('upload', 'alioss_endpoint')
                            );

                            $backgroundMusicFileName = basename($backgroundImgInfo['url']);
                            $uploadBackgroundMusicUrl = $ossClient->uploadFile(sysconfig('upload', 'alioss_bucket'), $backgroundMusicFileName, root_path() . 'public/' . $backgroundImgInfo['url']);

                            try {
                                $registerBackgroundImgMediaInfoRequest = new RegisterMediaInfoRequest([
                                    "inputURL" => $uploadBackgroundMusicUrl['info']['url'], 'MediaType' => 'image'
                                ]);
                                $runtime = new RuntimeOptions([]);
                                $registerBackgroundImgMediaInfoResult = $client->registerMediaInfoWithOptions($registerBackgroundImgMediaInfoRequest, $runtime);
                                if ($registerBackgroundImgMediaInfoResult->body->mediaId) {
                                    $background_img_media_id = $registerBackgroundImgMediaInfoResult->body->mediaId;
                                    $background_img_url = $uploadBackgroundMusicUrl['info']['url'];

                                    $backgroundImgModel->where(['id' => $value['background_img_id']])->update([
                                        'oss_url' => $uploadBackgroundMusicUrl['info']['url']
                                    ]);
                                }
                            } catch (\Exception $exception) {

                                $ClipProject = new ClipProject();
                                $clipTaskInfo = $clipMissionModel->where(['id' => $value['background_img_id']])->find();
                                if ($clipTaskInfo['error_msg']) {
                                    $error_msg = $clipTaskInfo['error_msg'] . '---:' . $exception->getMessage();
                                } else {
                                    $error_msg = $exception->getMessage();
                                }
                                /* if ($ClipProjectInfo) {
                                     // 部分成功
                                     $clipMissionModel->where(['id' => $value['id']])->update(['status' => 3, 'update_time' => time(), 'error_msg' => $error_msg]);
                                 } else {
                                     // 失败
                                     $clipMissionModel->where(['id' => $value['id']])->update(['status' => 4, 'update_time' => time(), 'error_msg' => $error_msg]);
                                 }*/

                                $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);
                                user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);
                                continue;
                            }


                            //$BackgroundMusicUrl = $uploadBackgroundMusicUrl['info']['url'];

                        }
                    }
                }
                // 注册视频和饮音频媒资
                foreach ($videoList as $videoValue) { // 视频提交媒资
                    $videoInfo = $videoModel->where(['id' => $videoValue['video_id']])->find();
                    if (strpos($videoInfo['result'], sysconfig('upload', 'alioss_bucket')) === false) {
                        $VideoPath = parse_url($videoInfo['result'], PHP_URL_PATH);
                        $videoFileName = basename($VideoPath);
                        $VideoUrl = 'https://' . sysconfig('upload', 'alioss_domain') . '/' . $videoFileName;
                        $ossClientUpload = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                            sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                            sysconfig('upload', 'alioss_endpoint')
                        );
                        if (!$ossClientUpload->doesObjectExist(sysconfig('upload', 'alioss_bucket'), $videoFileName)) {
                            $videoDownloadPath = root_path() . 'public/' . $videoFileName;
                            $ch = curl_init($videoInfo['result']);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                            $videoData = curl_exec($ch);
                            curl_close($ch);
                            // 将视频数据保存到本地文件
                            $videoFile = fopen($videoDownloadPath, 'wb');
                            fwrite($videoFile, $videoData);
                            fclose($videoFile);
                            $ossClient = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                                sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                                sysconfig('upload', 'alioss_endpoint')
                            );
                            $uploadVideoUrl = $ossClient->uploadFile(sysconfig('upload', 'alioss_bucket'), $videoFileName, $videoDownloadPath);
                            $videoInfo['result'] = $uploadVideoUrl['info']['url'];
                            // 上传阿里云后删除
                            unlink($videoDownloadPath);
                        } else {
                            $videoInfo['result'] = $VideoUrl;
                        }
                    }
                    $getMediaVideoInfoRequest = new GetMediaInfoRequest([
                        "inputURL" => $videoInfo['result']
                    ]);

                    $runtime = new RuntimeOptions([]);
                    // 复制代码运行请自行打印 API 的返回值
                    try { //  注册视频媒资
                        // https://guiji-shuziren.oss-cn-chengdu.aliyuncs.com/1747188457683_.mp4
                        $getMediaInfo = $client->getMediaInfoWithOptions($getMediaVideoInfoRequest, $runtime);
                        $video_media_id = $getMediaInfo->body->mediaInfo->mediaId;
                        $video_url = $videoInfo['result'];
                    } catch (\Exception $exception) {
                        try {
                            $registerVideoMediaInfoRequest = new RegisterMediaInfoRequest([
                                "inputURL" => $videoInfo['result'], 'MediaType' => 'video'
                            ]);
                            $runtime = new RuntimeOptions([]);
                            $registerVideoMediaInfoResult = $client->registerMediaInfoWithOptions($registerVideoMediaInfoRequest, $runtime);
                            if ($registerVideoMediaInfoResult->body->mediaId) {
                                $video_media_id = $registerVideoMediaInfoResult->body->mediaId;
                                $video_url = $videoInfo['result'];

                            }
                        } catch (\Exception $exception) {
                            $clipTaskInfo = $clipMissionModel->where(['id' => $value['id']])->find();
                            if ($clipTaskInfo['error_msg']) {
                                $error_msg = $clipTaskInfo['error_msg'] . '---' . $videoInfo['name'] . ':' . $exception->getMessage();
                            } else {
                                $error_msg = $exception->getMessage();
                            }
                            $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);



                            user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);
                            continue 2;
                        }
                    }
                    //
                    if ($videoInfo['audio_src']) {
                        $audioSrc = $videoInfo['audio_src'];
                    } else {
                        $audioInfo = FigureCompositeSound::where(['_id' => $videoInfo['sound_id']])->find();
                        $audioSrc = $audioInfo['url'];
                    }
                    if (strpos($audioSrc, sysconfig('upload', 'alioss_bucket')) === false) {
                        $audioFileName = basename($audioSrc);
                        //$audioSrc = 'https://' . sysconfig('upload', 'alioss_domain') . '/' . $audioFileName;
                        $ossClientUpload = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                            sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                            sysconfig('upload', 'alioss_endpoint')
                        );
                        //  if (!$ossClientUpload->doesObjectExist(sysconfig('upload', 'alioss_bucket'), $audioFileName)) {
                        $audioDownloadPath = root_path() . 'public/' . $audioFileName;
                        $ch = curl_init($audioSrc);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                        $audioData = curl_exec($ch);
                        curl_close($ch);
                        // 将视频数据保存到本地文件
                        $audioFile = fopen($audioDownloadPath, 'wb');
                        fwrite($audioFile, $audioData);
                        fclose($audioFile);
                        $ossClient = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                            sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                            sysconfig('upload', 'alioss_endpoint')
                        );
                        $uploadAudioUrl = $ossClient->uploadFile(sysconfig('upload', 'alioss_bucket'), time() . $audioFileName, $audioDownloadPath);

                        $audioSrc = $uploadAudioUrl['info']['url'];
                        // 上传阿里云后删除
                        unlink($audioDownloadPath);
                    }
                    //   }


                    if (empty($videoValue['content'])){
                        try {
                            $ASRJob['inputFile'] = $audioSrc;
                            $submitASRJob = new SubmitASRJobRequest($ASRJob);
                            $runtime = new RuntimeOptions([]);
                            $submitASRJobsResult = $client->submitASRJobWithOptions($submitASRJob, $runtime);
                            $audio_jobid = $submitASRJobsResult->body->jobId;
                        } catch (\Exception $exception) {
                            $clipTaskInfo = $clipMissionModel->where(['id' => $value['id']])->find();
                            if ($clipTaskInfo['error_msg']) {
                                $error_msg = $clipTaskInfo['error_msg'] . '---' . $videoInfo['name'] . ':' . $exception->getMessage();
                            } else {
                                $error_msg = $exception->getMessage();
                            }
                            $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);



                            user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);

                            continue 2;
                        }

                    }else{
                        $audio_jobid  ='';
                    }
                    // 提交音频内容 任务



                    try { //  注册音频媒资

                        $getMediaAudioInfoRequest = new GetMediaInfoRequest([
                            "inputURL" => $audioSrc
                        ]);
                        $getMediaAudioInfo = $client->getMediaInfoWithOptions($getMediaAudioInfoRequest, $runtime);
                        $audio_media_id = $getMediaAudioInfo->body->mediaInfo->mediaId;
                        $audio_url = $audioSrc;
                    } catch (\Exception $exception) {

                        try {
                            $registerMusicMediaInfoRequest = new RegisterMediaInfoRequest([
                                "inputURL" => $audioSrc,
                                'MediaType' => 'audio'
                            ]);
                            $runtime = new RuntimeOptions([]);
                            $registerMusicMediaInfoResult = $client->registerMediaInfoWithOptions(
                                $registerMusicMediaInfoRequest, $runtime);


                            $audio_media_id = $registerMusicMediaInfoResult->body->mediaId;
                            $audio_url = $audioSrc;
                        } catch (\Exception $exception) {

                            $clipTaskInfo = $clipMissionModel->where(['id' => $value['id']])->find();
                            if ($clipTaskInfo['error_msg']) {
                                $error_msg = $clipTaskInfo['error_msg'] . '---' . $videoInfo['name'] . ':' . $exception->getMessage();
                            } else {
                                $error_msg = $exception->getMessage();
                            }
                            $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);

                            /*if ($ClipProjectInfo) {
                                // 部分成功
                                $clipMissionModel->where(['id' => $value['id']])->update(['status' => 3, 'update_time' => time(), 'error_msg' => $error_msg]);
                            } else {
                                // 失败
                                $clipMissionModel->where(['id' => $value['id']])->update(['status' => 4, 'update_time' => time(), 'error_msg' => $error_msg]);
                            }*/

                            user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);

                            continue 2;
                        }
                    }

                    for ($i = 0; $i < $value['multiple']; $i++) {
                        $clipProjectData[] = [  // 固定视频数据
                            'mission_id' => $value['id'],
                            'uid' => $value['uid'],
                            'create_time' => time(),
                            'audio_jobid' => $audio_jobid,
                            'video_media_id' => $video_media_id,
                            'video_url' => $video_url,
                            'audio_media_id' => $audio_media_id,
                            'audio_url' => $audio_url,
                            'background_img_media_id' => $background_img_media_id,
                            'background_img_url' => $background_img_url,
                            'clip_video_id' => $videoValue['id']

                        ];

                    }
                }

                // 背景图片媒资
                $clipBackgroundMusic = new ClipBackgroundMusic();
                $clipBackgroundMusicArray = $clipBackgroundMusic->where(['mission_id' => $value['id']])->select();
                foreach ($clipBackgroundMusicArray as $clipBackgroundMusicValue) {
                    $clipBackgroundMusicInfo = $clipBackgroundMusic->where('media_id', '<>', '')
                        ->where(['primary_url' => $clipBackgroundMusicValue['primary_url']])
                        ->find();
                    if ($clipBackgroundMusicInfo) {
                        $clipBackgroundMusic->where(['id' => $clipBackgroundMusicValue['id']])->update(['media_id' => $clipBackgroundMusicInfo['media_id']]);

                    } else {
                        $background_musicUrl = str_replace("\\", "", $clipBackgroundMusicValue['primary_url']); // 使用双反斜杠进行转义
                        $backgroundMusicPath = parse_url($background_musicUrl, PHP_URL_PATH);
                        $backgroundMusicFileName = basename($backgroundMusicPath);
                        $backgroundMusicDownloadPath = root_path() . 'public/' . $backgroundMusicFileName . '.mp3';
                        $ch = curl_init($background_musicUrl);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                        $videoData = curl_exec($ch);
                        curl_close($ch);
                        // 将视频数据保存到本地文件
                        $videoFile = fopen($backgroundMusicDownloadPath, 'wb');
                        fwrite($videoFile, $videoData);
                        fclose($videoFile);
                        $ossClient = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                            sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                            sysconfig('upload', 'alioss_endpoint')
                        );
                        $uploadBackgroundMusicUrl = $ossClient->uploadFile(sysconfig('upload', 'alioss_bucket'), $backgroundMusicFileName . '.mp3', $backgroundMusicDownloadPath);
                        $BackgroundMusicUrl = $uploadBackgroundMusicUrl['info']['url'];
                        // 上传阿里云后删除
                        unlink($backgroundMusicDownloadPath);
                        try { //  注册背景音乐媒资
                            $getMediaBackgroundMusicRequest = new GetMediaInfoRequest([
                                "inputURL" => $BackgroundMusicUrl
                            ]);
                            $getMediaBackgroundMusicInfo = $client->getMediaInfoWithOptions($getMediaBackgroundMusicRequest, $runtime);
                            $clipBackgroundMusic->where(['primary_url' => $clipBackgroundMusicValue['primary_url']])
                                ->where(['mission_id' => $value['id']])
                                ->update([
                                    'media_id' => $getMediaBackgroundMusicInfo->body->mediaInfo->mediaId,
                                    'oss_url' => $BackgroundMusicUrl,
                                ]);

                        } catch (\Exception $exception) {
                            try {
                                $registerBackMusicMediaInfoRequest = new RegisterMediaInfoRequest([
                                    "inputURL" => $BackgroundMusicUrl,
                                    'MediaType' => 'audio']);
                                $runtime = new RuntimeOptions([]);
                                $registerBackMusicMediaInfoResult = $client->registerMediaInfoWithOptions($registerBackMusicMediaInfoRequest, $runtime);

                                $clipBackgroundMusic->where(['primary_url' => $clipBackgroundMusicValue['primary_url']])
                                    ->where(['id' => $clipBackgroundMusicValue['id']])
                                    ->update([
                                        'media_id' => $registerBackMusicMediaInfoResult->body->mediaId,
                                        'oss_url' => $BackgroundMusicUrl,
                                    ]);

                            } catch (\Exception $exception) {

                                user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);
                                $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);

                                continue 2;

                            }
                        }
                    }
                }

                $clipMaterial = new ClipMaterial();
                $clipMaterialArray = $clipMaterial->where(['mission_id' => $value['id']])->select();
                foreach ($clipMaterialArray as $clipMaterialValue) {
                    try {
                        $getMediaMaterialRequest = new GetMediaInfoRequest([
                            "inputURL" => $clipMaterialValue['material_url']
                        ]);
                        $getMediaMaterialInfo = $client->getMediaInfoWithOptions($getMediaMaterialRequest, $runtime);
                        $clipMaterial->where(['id' => $clipMaterialValue['id']])
                            ->where(['mission_id' => $value['id']])
                            ->update([
                                'media_id' => $getMediaMaterialInfo->body->mediaInfo->mediaId,
                            ]);

                    } catch (\Exception $exception) {
                        try {
                            $registerMaterialMediaInfoRequest = new RegisterMediaInfoRequest([
                                "inputURL" => $clipMaterialValue['material_url'],
                                'MediaType' => 'video']);
                            $runtime = new RuntimeOptions([]);
                            $registerMaterialMediaInfoResult = $client->registerMediaInfoWithOptions($registerMaterialMediaInfoRequest, $runtime);
                            $clipMaterial->where(['id' => $clipMaterialValue['id']])
                                ->where(['mission_id' => $value['id']])
                                ->update([
                                    'media_id' => $registerMaterialMediaInfoResult->body->mediaId,
                                ]);

                        } catch (\Exception $exception) {

                            user_balance_used($value['uid'], $value['log_no'], 3, 11, $videoCount * $value['multiple']);

                            $clipMissionModel->where(['id' => $value['id']])->update(['status' => 5, 'update_time' => time(), 'error_msg' => $error_msg]);

                            continue 2;
                        }
                    }
                }


                if ($clipProjectData) {

                    $clipProjectModel->insertAll($clipProjectData);
                    $clipMissionModel->where(['id' => $value['id']])->update(['status' => 1]);
                }
                //  $clipMissionModel->commit();
            } catch (\Exception $exception) {
                $clipMissionModel->where(['id' => $value['id']])->update([ 'update_time' => time(), 'error_msg' => $exception->getMessage()]);
                // $clipMissionModel->rollback();
                echo $exception->getMessage();
            }
        }

    }

    /**
     *  提交剪辑工程
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function clipVideoResource()
    {


        $ClipProjectModel = new ClipProject();
        $clipMissionModel = new ClipMission();
        $clipModelModel = new ClipModel();
        $clipMissionData = $clipMissionModel->where(['status' => 1])->select();
        foreach ($clipMissionData as $clipMissionValue) {

            $clipMissionModel->where(['id' => $clipMissionValue['id']])->update(['status' => 2]);// 视频剪辑中
            $clipTaskList = $ClipProjectModel->where(['status' => 1, 'mission_id' => $clipMissionValue['id']])->select();

            $modelId = explode(',', $clipMissionValue['model_id']);
            $clipMaterialModel = new ClipMaterial();

            // 素材
            $clipMaterialData = $clipMaterialModel->where(['mission_id' => $clipMissionValue['id']])->select()->toArray();
            $newClipMaterialData = $clipMaterialData;

            // 背景音乐
            $clipBackgroundMusicModel = new ClipBackgroundMusic();
            $clipBackgroundMusicData = $clipBackgroundMusicModel->where(['mission_id' => $clipMissionValue['id']])->select()->toArray();
            // 标题
            $clipTitleModel = new ClipTitle();
            $clipTitleData = $clipTitleModel->where(['mission_id' => $clipMissionValue['id']])->select()->toArray();
            $clipModelArray = $clipModelModel->where('id', 'in', $modelId)->select();


            foreach ($clipTaskList as $clipTaskValue) {

                $ClipProjectModel->where(['id' => $clipTaskValue['id']])->update(['status' => 2]); // 任务剪辑中
                /* try {*/
                $timeline = [];
                $SubtitleTrackClips = [];
                $keynoteContentDataArray =[];
                $keynoteContentData =[];
                $config = new \Darabonba\OpenApi\Models\Config([
                    // 您的AccessKey ID
                    "accessKeyId" => sysconfig('upload', 'alioss_access_key_id'),
                    // 您的AccessKey Secret
                    "accessKeySecret" => sysconfig('upload', 'alioss_access_key_secret'),
                    'endpoint' => sysconfig('upload', 'alioss_clip_endpoint')//sysconfig('upload', 'alioss_clip_endpoint'),
                ]);

                $client = new ICE($config);
                $clipVideo = new ClipVideo();
                $content = [];
                $clipVideoInfo =  $clipVideo->where(['id' => $clipTaskValue['clip_video_id']])->find();

                $modelCount = count($clipModelArray);
                $modelIndex = rand(0, $modelCount - 1);
                $modelInfo = $clipModelArray[$modelIndex];
                $runtime = new RuntimeOptions([]);
                if (empty($clipVideoInfo['content'])){
                    $audioSmartHandleJobRequest = new GetSmartHandleJobRequest([
                        "jobId" => $clipTaskValue['audio_jobid']
                    ]);

                    $audioSmartHandleJobResult = $client->getSmartHandleJobWithOptions($audioSmartHandleJobRequest, $runtime);
                    if ($audioSmartHandleJobResult->body->state != 'Finished') {
                        $ClipProjectModel->where(['id' => $clipTaskValue['id']])->update(['status' => 1]);
                        $clipMissionModel->where(['id' => $clipMissionValue['id']])->update(['status' => 1]);
                        continue 2;
                    }
                    $textArray = json_decode($audioSmartHandleJobResult->body->jobResult->aiResult);


                    foreach ($textArray as $textValue) {

                        $content[] = $textValue->content;

                        $contentData = json_decode($modelInfo['captions'], true);
                        $contentData['TimelineIn'] = $textValue->from;
                        $contentData['TimelineOut'] = $textValue->to;
                        $contentData['TextWidth'] = 0.9;
                        $contentData['Content'] = $textValue->content;
                        $SubtitleTrackClips[] = $contentData;

                    }

                }else{
                    $countArray =  json_decode($clipVideoInfo['content'] , true);
                    foreach ($countArray as $countValue){
                        $content[] = $countValue['Content'];
                        $contentData = json_decode($modelInfo['captions'], true);
                        $contentData['TimelineIn'] = $countValue['TimelineIn'];
                        $contentData['TimelineOut'] = $countValue['TimelineOut'];
                        $contentData['TextWidth'] = 0.9;


                        $startSting = '/b1/'; //
                        $startAddSting  ='b1\\\\\\\\1c&'.$this->keywordColour[$modelIndex].'&';

                        $endSting = '/b0/'; //
                        $endAddSting  ='b0\\\\\\\\1c';
                        $contentSring = preg_replace($startSting, $startAddSting, $countValue['Content']); // 只替换第一个匹配项
                        $contentSring =preg_replace($endSting, $endAddSting, $contentSring);

                        $contentData['Content'] = $contentSring;
                        $SubtitleTrackClips[] = $contentData;
                    }

                    if (!empty($clipVideoInfo['keynote_content'])){
                        $keynote_content =  json_decode($clipVideoInfo['keynote_content'] , true);
                        $position  = $this->position;
                        foreach ($keynote_content as $keynote_contentValue){

                            $position = array_values($position);
                            if (empty($position)){
                                $position  = $this->position;
                            }
                            $keynoteContentData  = $position[0];
                            unset($position[0]);
                            //  $contentData = json_decode($modelInfo['captions'], true);
                            $keywordFontColor = json_decode($modelInfo['keyword'], true);
                            $keynoteContentData['TimelineIn'] = $keynote_contentValue['TimelineIn'];
                            $keynoteContentData['TimelineOut'] = $keynote_contentValue['TimelineOut'];



                            $keynoteContentData['Content'] = $keynote_contentValue['Content'];
                            $keynoteContentData['Font'] = 'FZLanTingHeiS-R-GB';
                            $keynoteContentData['TextWidth'] = '1';
                            $keynoteContentData['FontColor'] = $keywordFontColor['FontColor'];
                            $keynoteContentData['Color'] = $keywordFontColor['Color'];
                            $keynoteContentData['FontSize'] = '22';
                            $keynoteContentData['FontFace']['Italic'] = 'true';
                            $keynoteContentData['FontFace']['Underline'] = 'false';
                            $keynoteContentData['FontFace']['Bold'] = 'true';
                            $keynoteContentData['AdaptMode'] = 'AutoWrap';
                            $keynoteContentData['AaiMotionIn'] = $keynote_contentValue['TimelineOut'] -$keynote_contentValue['TimelineIn'];
                            $positionCount  = count($this->AaiMotionInEffect);
                            $AaiMotionInEffectround =  mt_rand(0,$positionCount-1);
                            $keynoteContentData['AaiMotionInEffect']  = $this->AaiMotionInEffect[$AaiMotionInEffectround];
                            $keynoteContentDataArray[] =$keynoteContentData;

                        }


                    }
                }


                $timeline['AudioTracks'][0]['AudioTrackClips'][0]['MediaId'] = $clipTaskValue['audio_media_id'];
                $timeline['AudioTracks'][0]['AudioTrackClips'][0]['Effects'][0]['Type'] = 'Volume';
                $timeline['AudioTracks'][0]['AudioTrackClips'][0]['Effects'][0]['Gain'] = 2;
                if ($clipBackgroundMusicData) {
                    $clipBackgroundMusicCount = count($clipBackgroundMusicData);
                    $clipBackgroundMusicIndex = rand(0, $clipBackgroundMusicCount - 1);
                    $clipBackgroundMusic = $clipBackgroundMusicData[$clipBackgroundMusicIndex];
                    $timeline['AudioTracks'][1]['AudioTrackClips'][0]['MediaId'] = $clipBackgroundMusic['media_id'];
                    $timeline['AudioTracks'][1]['AudioTrackClips'][0]['Effects'][0]['Type'] = 'Volume';
                    $timeline['AudioTracks'][1]['AudioTrackClips'][0]['Effects'][0]['Gain'] =  (float)$clipBackgroundMusic['volume'];
                    $timeline['AudioTracks'][1]['AudioTrackClips'][0]['LoopMode'] = true;
                }
                $clipTitleInfo =[];
                if ($clipTitleData) {
                    $clipTitleDataCount = count($clipTitleData);
                    $clipTitleIndex = rand(0, $clipTitleDataCount - 1);
                    $clipTitleInfo = $clipTitleData[$clipTitleIndex];

                    $titleData = json_decode($modelInfo['title'], true);
                    $titleData['Content'] = $clipTitleInfo['title'];

                    if ($clipMissionValue['title_show_time'] != 0) {
                        $titleData['TimelineIn'] = 0;
                        $titleData['TimelineOut'] = $clipMissionValue['title_show_time'];
                    }

                    $SubtitleTrackClips[] = $titleData;
                }

                $timeline['SubtitleTracks'][0]['SubtitleTrackClips'] = $SubtitleTrackClips;
                if ($keynoteContentDataArray){
                    $timeline['SubtitleTracks'][1]['SubtitleTrackClips'] = $keynoteContentDataArray;
                }
                $getMediaAudioInfoRequest = new GetMediaInfoRequest([
                    "mediaId" => $clipTaskValue['audio_media_id']
                ]);
                $getMediaAudioInfo = $client->getMediaInfoWithOptions($getMediaAudioInfoRequest, $runtime);
                $duration = $getMediaAudioInfo->body->mediaInfo->fileInfoList[0]->fileBasicInfo->duration;

                // 素材数量
                /*          $clipMaterialCount = count($clipMaterialData);*/
                if ($clipTaskValue['background_img_media_id']) {
                    $background_img['MediaId'] = $clipTaskValue['background_img_media_id'];
                    $background_img['Type'] = 'GlobalImage';
                    $timeline['VideoTracks'][0]['VideoTrackClips'][] = $background_img;
                }
                if (count($clipMaterialData) > 0) {
                    $clipLoopNumber = ceil($duration / 3); // 剪辑需要循环几次
                    $getMediaVideoInfoRequest = new GetMediaInfoRequest([
                        "mediaId" => $clipTaskValue['video_media_id']
                    ]);
                    $getMediaVideoInfo = $client->getMediaInfoWithOptions($getMediaVideoInfoRequest, $runtime);
                    $Videoduration = $getMediaVideoInfo->body->mediaInfo->fileInfoList[0]->fileBasicInfo->duration;

                    $data['data'] = [];
                    for ($clipLoopStart = 0; $clipLoopStart < $clipLoopNumber; $clipLoopStart++) {

                        $surplusDuration = bcsub($Videoduration, bcmul($clipLoopStart, 3, 4), 4);
                        if ($surplusDuration < 3) {

                            //  $data = $this->roudsecond($clipTaskValue['video_media_id'], $Videoduration, $data['data'], $surplusDuration);
                            $videoData['MediaId'] = $clipTaskValue['video_media_id'];
                            $videoData['Type'] = 'Video';
                            $videoData['In'] = bcmul($clipLoopStart, 3, 4); //(float)bcdiv($data['startDuration'], 2, 4);
                            $videoData['Out'] = bcadd(bcmul($clipLoopStart, 3, 4), $surplusDuration, 4); //(float)bcdiv($data['endDuration'], 2, 4);

                            if ($clipTaskValue['background_img_media_id']) {
                                $videoData['Effects'][0]['Type'] = 'Background';
                                $videoData['Effects'][1]['Type'] = 'Volume';
                                $videoData['Effects'][1]['Gain'] = 0;

                            } else {
                                $videoData['Effects'][0]['Type'] = 'Volume';
                                $videoData['Effects'][0]['Gain'] = 0;
                            }
                            if ($clipTaskValue['background_img_media_id']) {
                                $timeline['VideoTracks'][1]['VideoTrackClips'][] = $videoData;
                            } else {
                                $timeline['VideoTracks'][0]['VideoTrackClips'][] = $videoData;
                            }
                        } else {
                            if ($clipLoopStart % 2 > 0) {
                                if ($newClipMaterialData) {
                                    $newClipMaterialData = array_values($newClipMaterialData);
                                    $MaterialCount = count($newClipMaterialData);
                                } else {
                                    $newClipMaterialData = $clipMaterialData;
                                    $MaterialCount = count($newClipMaterialData);
                                }
                                $MaterialIndex = rand(0, $MaterialCount - 1);
                                $MaterialInfo = $newClipMaterialData[$MaterialIndex];
                                unset($newClipMaterialData[$MaterialIndex]);
                                $getMediaMaterialInfoRequest = new GetMediaInfoRequest([
                                    "mediaId" => $MaterialInfo['media_id']
                                ]);
                                $getMediaMaterialInfo = $client->getMediaInfoWithOptions($getMediaMaterialInfoRequest, $runtime);
                                $Materiaduration = $getMediaMaterialInfo->body->mediaInfo->fileInfoList[0]->fileBasicInfo->duration;


                                $data = $this->roudsecond($MaterialInfo['media_id'], $Materiaduration, $data['data'], $surplusDuration);
                                $videoData['MediaId'] = $MaterialInfo['media_id'];
                                $videoData['Type'] = 'Video';
                                $videoData['In'] = (float)bcdiv($data['startDuration'], 2, 4);
                                $videoData['Out'] = (float)bcdiv($data['endDuration'], 2, 4);
                                if ($clipTaskValue['background_img_media_id']) {
                                    $videoData['Effects'][0]['Type'] = 'Background';
                                    $videoData['Effects'][1]['Type'] = 'Volume';
                                    $videoData['Effects'][1]['Gain'] = 0;

                                } else {
                                    $videoData['Effects'][0]['Type'] = 'Volume';
                                    $videoData['Effects'][0]['Gain'] = 0;
                                }
                                if ($clipTaskValue['background_img_media_id']) {
                                    $timeline['VideoTracks'][1]['VideoTrackClips'][] = $videoData;
                                } else {
                                    $timeline['VideoTracks'][0]['VideoTrackClips'][] = $videoData;
                                }
                            } else {

                                //$data = self::roudsecond($clipTaskValue['video_media_id'], $Videoduration, $data['data'], $surplusDuration);

                                $videoData['MediaId'] = $clipTaskValue['video_media_id'];
                                $videoData['Type'] = 'Video';
                                /* $videoData['In'] = (float)bcdiv($data['startDuration'], 2, 4);
                                 $videoData['Out'] = (float)bcdiv($data['endDuration'], 2, 4);*/
                                $videoData['In'] = bcmul($clipLoopStart, 3, 4); //(float)bcdiv($data['startDuration'], 2, 4);
                                $videoData['Out'] = bcadd(bcmul($clipLoopStart, 3, 4), 3, 4); //(float)bcdiv($data['endDuration'], 2, 4);

                                if ($clipTaskValue['background_img_media_id']) {
                                    $videoData['Effects'][0]['Type'] = 'Background';
                                    $videoData['Effects'][1]['Type'] = 'Volume';
                                    $videoData['Effects'][1]['Gain'] = 0;

                                } else {
                                    $videoData['Effects'][0]['Type'] = 'Volume';
                                    $videoData['Effects'][0]['Gain'] = 0;
                                }
                                if ($clipTaskValue['background_img_media_id']) {
                                    $timeline['VideoTracks'][1]['VideoTrackClips'][] = $videoData;
                                } else {
                                    $timeline['VideoTracks'][0]['VideoTrackClips'][] = $videoData;
                                }
                            }
                        }


                    }
                } else {
                    $videoData['MediaId'] = $clipTaskValue['video_media_id'];
                    $videoData['Type'] = 'Video';
                    // $videoData['In'] = (float)bcdiv($data['startDuration'], 2, 4);
                    //  $videoData['Out'] = (float)bcdiv($data['endDuration'], 2, 4);

                    if ($clipTaskValue['background_img_media_id']) {
                        $videoData['Effects'][0]['Type'] = 'Background';
                        $videoData['Effects'][1]['Type'] = 'Volume';
                        $videoData['Effects'][1]['Gain'] = 0;

                    } else {
                        $videoData['Effects'][0]['Type'] = 'Volume';
                        $videoData['Effects'][0]['Gain'] = 0;
                    }
                    if ($clipTaskValue['background_img_media_id']) {
                        $timeline['VideoTracks'][1]['VideoTrackClips'][] = $videoData;
                    } else {
                        $timeline['VideoTracks'][0]['VideoTrackClips'][] = $videoData;
                    }
                }

                $mediaURL = 'https://' . sysconfig('upload', 'alioss_domain') . '/' . uniqid() . '.mp4';

                $timeline['FECanvas'] = ["Height" => 450, "Width" => 253.125];
                $outputMediaConfig = [
                    'Width' => '720',
                    'Height' => '1280',
                    'mediaURL' => $mediaURL,
                ];


                $MediaProducingJobrequest = new SubmitMediaProducingJobRequest();

                $MediaProducingJobrequest->outputMediaConfig = json_encode($outputMediaConfig);
                $MediaProducingJobrequest->timeline = json_encode($timeline);
                $response = $client->submitMediaProducingJob($MediaProducingJobrequest);


                $ClipProjectModel->where(['id' => $clipTaskValue['id']])->update([
                    'status' => 3,
                    'complete_jobid' => $response->body->jobId,
                    'complete_video' => $mediaURL,
                    'title' => isset ($clipTitleInfo['title'])?$clipTitleInfo['title']:'' ,
                    'content' => implode(',', $content)
                ]);//生成中
                $clipMissionModel->where(['id' => $clipMissionValue['id']])->update(['status' => 3]);//生成中
                /* } catch (\Exception $exception) {
                     $ClipProjectModel->where(['id' => $clipTaskValue['id']])->update([
                         'status' => 4,
                         // 'complete_jobid' => $response->body->jobId,
                         'error_msg' => $exception->getMessage()
                     ]);//生成失败
                     $clipMissionInfo = $clipMissionModel->where(['id' => $clipMissionValue['id']])->find();
                     if ($clipMissionInfo['status'] == 4 || $clipMissionInfo['status'] == 6) {
                         $clipMissionModel->where(['id' => $clipMissionValue['id']])->update(['status' => 6]);//生成中

                     } else {
                         $clipMissionModel->where(['id' => $clipMissionValue['id']])->update(['status' => 5]);//生成中

                     }


                 }*/
                //
            }

        }

    }

    public function roudsecond($media_id, $video_duration, $data, $surplusDuration)
    {

        $amplifyDuration = $video_duration * 2;// 单位为0.5 先放大一倍
        $startDuration = mt_rand(0, $amplifyDuration);

        if ($video_duration - $startDuration < 6) {
            return $this->roudsecond($media_id, $video_duration, $data, $surplusDuration);
        }
        if (!array_key_exists($media_id, $data)) {
            $data[$media_id] = [];
        }

        if (in_array($startDuration, $data[$media_id])) {

            return $this->roudsecond($media_id, $video_duration, $data, $surplusDuration);
        } else {

            $data[$media_id][] = $startDuration;
            if ($surplusDuration > 3) {
                $endDuration = $startDuration + 6;
            } else {
                $endDuration = bcadd($startDuration, bcmul($surplusDuration, 2, 4), 4);
            }
        }
        return ['data' => $data, 'startDuration' => $startDuration, 'endDuration' => $endDuration];

        //$endDuration = $startDuration + 6;


    }

    /**
     *  查询剪辑任务
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */

    public function selectClipVideo()
    {
        $ClipProjectModel = new ClipProject();
        $clipVideo = $ClipProjectModel->where(['status' => 3])->select();

        $clipTaskModel = new ClipMission();
        //$TouchSetting = platform_setting($value['plat_id'], TouchSettingKey::BASE);

        foreach ($clipVideo as $value) {

            try {
                $config = new \Darabonba\OpenApi\Models\Config([
                    // 您的AccessKey ID
                    "accessKeyId" => sysconfig('upload', 'alioss_access_key_id'),
                    // 您的AccessKey Secret
                    "accessKeySecret" => sysconfig('upload', 'alioss_access_key_secret'),
                    'endpoint' => sysconfig('upload', 'alioss_clip_endpoint')//sysconfig('upload', 'alioss_clip_endpoint'),
                ]);
                $client = new ICE($config);
                $request = new GetMediaProducingJobRequest();
                $request->jobId = $value['complete_jobid'];
                $response = $client->getMediaProducingJob($request);
                $request = new GetMediaInfoRequest();

                if ($response->body->mediaProducingJob->status == 'Success') {
                    $request->mediaId = $response->body->mediaProducingJob->mediaId;
                    $MediaInfo = $client->getMediaInfo($request);
                    $clipTaskInfo = $clipTaskModel->where(['id' => $value['mission_id']])->find();
                    if ($clipTaskInfo['status'] == 6 || $clipTaskInfo['status'] == 5) { // 状态等于5表示失败。现在有成功说明部分合成，状态 6 就是部分合成
                        $clipTaskModel->where(['id' => $value['mission_id']])->update([
                            'status' => 6,
                            'update_time' => time(),
                        ]);
                    } else {
                        $clipTaskModel->where(['id' => $value['mission_id']])->update([
                            'status' => 4,
                            'update_time' => time(),
                        ]);
                    }
                    if ($MediaInfo->body->mediaInfo->mediaBasicInfo->coverURL) {
                        $ClipProjectModel->where(['id' => $value['id']])->update([
                            'status' => 5,
                            'complete_cover' => $uri_without_query = preg_replace('/\?.*/', '', $MediaInfo->body->mediaInfo->mediaBasicInfo->coverURL)

                        ]);
                    } else {
                        continue;
                    }
                    $userModel = new FigureUser();
                    $userInfo = $userModel->where(['id' => $value['uid']])->find();
                    $generateData ['openid'] = $userInfo['openid'];
                    $generateData['thing14'] = '二次剪辑';
                    $generateData['thing4'] = '视频合成成功'  ;
                    $generateData['date3'] = date('Y-m-d H:i', time());
                    $generateSuccess = new Task($generateData);
                    $generateSuccess->send();
                };
                if ($response->body->mediaProducingJob->status == 'Fail' || $response->body->mediaProducingJob->status == 'Failed') { // 失败同步修改 任务状态
                    $ClipProjectModel->where(['id' => $value['id']])->update(['status' => 4]);
                    $clipVideo = $clipTaskModel->where(['id' => $value['mission_id']])->find();
                    user_balance_used($value['uid'], $value['log_no'], 3, 11, 1);
                    if ($clipVideo['status'] == 6 || $clipVideo['status'] == 4) { // 有合成成功的视频就 是部分合成没有 状态就是失败
                        $clipTaskModel->where(['id' => $value['mission_id']])->update(['status' => 6, 'update_time' => time()]);
                    } else {
                        $clipTaskModel->where(['id' => $value['mission_id']])->update(['status' => 5, 'update_time' => time()]);
                    }
                }

            } catch (Exception $exception) {
                echo $exception->getMessage();
                continue;
            }
        }
        echo '二次剪辑查询合成状态<br>';
    }

    public function clipTaskList()
    {
        try {
            $uid = input('uid');
            $request = $this->request;
            $param = $request->param();
            $user = FigureUser::where('id', $uid)->find();
            if (empty($user)) {
                return result(-1, '用户不存在');
            }

            $pindex = max(1, intval(input('page')));
            $psize = empty(input('psize')) ? 10 : intval(input('psize'));

            $is_publishe = input('is_publishe');

            $where['uid'] = $uid;

           if(isset($param['id']) && !empty($param['id']) ){
               $where['id'] = $param['id'];
           }
            if ($is_publishe == 1){
                $where['is_douyin'] = 1;
            }elseif ($is_publishe == 2){
                $where['is_kuaishou'] = 1;
            }elseif ($is_publishe == 3){
                $where['is_shipinghao'] = 1;
            }elseif ($is_publishe == 4){
                $where['is_xiaohongshu'] = 1;
            }

            $status = input('status');

            $ClipTaskModel = new  ClipMission();
            if ($status == 1) {
                $total = $ClipTaskModel->where($where)->where('status', 'in', ['4,6'])->count();
            } else {
                $total = $ClipTaskModel->where($where)->count();
            }
            if ($total) {
                if ($status == 1) {
                    $list = $ClipTaskModel->where($where)->order('create_time', 'desc')
                        ->where('status', 'in', ['4,6'])
                        ->limit(($pindex - 1) * $psize, $psize)
                        ->select();
                } else {
                    $list = $ClipTaskModel->where($where)->order('create_time', 'desc')
                        ->limit(($pindex - 1) * $psize, $psize)
                        ->select();
                }
                $clipVideoModel = new ClipProject();
                $ClipTitleModel = new ClipTitle();
                foreach ($list as $key => $value) {

                    $clipVideoWhere['mission_id'] = $value['id'];


                    if ($is_publishe) {
                        if ($is_publishe == 1) {
                            $clipVideoWhere['is_douyin'] = 1;
                        } elseif ($is_publishe == 2) {
                            $clipVideoWhere['is_kuaishou'] = 1;

                        } elseif ($is_publishe == 3) {
                            $clipVideoWhere['is_shipinghao'] = 1;

                        } elseif ($is_publishe == 4) {
                            $clipVideoWhere['is_xiaohongshu'] = 1;

                        }
                    }
                    $list[$key]['video_count'] = $clipVideoModel->where(['mission_id' => $value['id']])->where($clipVideoWhere)->count();
                    $title = $ClipTitleModel->where(['mission_id' => $value['id']])->find();
                    if ($title){
                        $list[$key]['title'] = $title['title'];
                    }else{
                        $list[$key]['title'] = '';
                    }
                }
            } else {
                $list = array();
            }

            $totalPage = ceil($total / $psize);

            return result(0, 'success', array(
                'list' => $list,
                'total' => $total,
                'pindex' => $pindex,
                'psize' => $psize,
                'totalPage' => $totalPage
            ));
        } catch (\Exception $e) {
            return result(-1, '异常' . $e->getLine() . "--->" . $e->getMessage());
            exit();
        }
    }

    public function clipVideoList()
    {
        try {
            $uid = input('uid');

            $user = FigureUser::where('id', $uid)->find();
            if (empty($user)) {
                return result(-1, '用户不存在');
            }
            $pindex = max(1, intval(input('page')));
            $psize = empty(input('psize')) ? 10 : intval(input('psize'));

            $where['uid'] = $uid;
            $where['mission_id'] = input('id');
            //$where['status'] = 3;
            $ClipResourceModel = new  ClipProject();
            $total = $ClipResourceModel->where($where)->count();
            if ($total) {
                $list = $ClipResourceModel->where($where)->order('create_time', 'desc')
                    ->limit(($pindex - 1) * $psize, $psize)
                    ->select();
            } else {
                $list = array();
            }

            $totalPage = ceil($total / $psize);

            return result(0, 'success', array(
                'list' => $list,
                'total' => $total,
                'pindex' => $pindex,
                'psize' => $psize,
                'totalPage' => $totalPage
            ));
        } catch (\Exception $e) {
            return result(-1, '异常' . $e->getLine() . "--->" . $e->getMessage());
            exit();
        }
    }

    public function submitSoundConent()
    {
        $request = $this->request;
        $param = $request->param();
        $videoModel = new  FigureVideo();
        $videoInfo = $videoModel->where(['id' => $param['id']])->find();
        if ($videoInfo['audio_src']) {
            $audioSrc = $videoInfo['audio_src'];
        } else {
            $audioInfo = FigureCompositeSound::where(['_id' => $videoInfo['sound_id']])->find();
            $audioSrc = $audioInfo['url'];
        }
        if (strpos($audioSrc, sysconfig('upload', 'alioss_bucket')) === false) {
            $audioFileName = basename($audioSrc);

            $ossClientUpload = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                sysconfig('upload', 'alioss_endpoint')
            );
            //  if (!$ossClientUpload->doesObjectExist(sysconfig('upload', 'alioss_bucket'), $audioFileName)) {
            $audioDownloadPath = root_path() . 'public/' . $audioFileName;
            $ch = curl_init($audioSrc);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            $audioData = curl_exec($ch);
            curl_close($ch);
            // 将视频数据保存到本地文件
            $audioFile = fopen($audioDownloadPath, 'wb');
            fwrite($audioFile, $audioData);
            fclose($audioFile);
            $ossClient = new OssClient(sysconfig('upload', 'alioss_access_key_id'),
                sysconfig('upload', 'alioss_access_key_secret'),//'oss-cn-hangzhou.aliyuncs.com'
                sysconfig('upload', 'alioss_endpoint')
            );
            $uploadAudioUrl = $ossClient->uploadFile(sysconfig('upload', 'alioss_bucket'), time() . $audioFileName, $audioDownloadPath);

            $audioSrc = $uploadAudioUrl['info']['url'];
            // 上传阿里云后删除
            unlink($audioDownloadPath);
        }
        $config = new \Darabonba\OpenApi\Models\Config([
            // 您的AccessKey ID
            "accessKeyId" => sysconfig('upload', 'alioss_access_key_id'),
            // 您的AccessKey Secret
            "accessKeySecret" => sysconfig('upload', 'alioss_access_key_secret'),
            'endpoint' => sysconfig('upload', 'alioss_clip_endpoint'),
        ]);
        $client = new ICE($config);
        try {
            $ASRJob['inputFile'] = $audioSrc;
            $submitASRJob = new SubmitASRJobRequest($ASRJob);
            $runtime = new RuntimeOptions([]);
            $submitASRJobsResult = $client->submitASRJobWithOptions($submitASRJob, $runtime);
            $audio_jobid = $submitASRJobsResult->body->jobId;
            $ClipSoundContentModel = new ClipSoundContent();
            $data = [
                'video_id' => $param['id'],
                'url' => $audioSrc,
                'job_id' => $audio_jobid,
                'create_time' => time()
            ];
            $ClipSoundContentModel->save($data);
            return result(0, 'success', $ClipSoundContentModel);
        } catch (\Exception $exception) {

            return result(-1, $exception->getMessage());
        }


    }

    public function getSoundConent()
    {
        $request = $this->request;
        $param = $request->param();
        $config = new \Darabonba\OpenApi\Models\Config([
            // 您的AccessKey ID
            "accessKeyId" => sysconfig('upload', 'alioss_access_key_id'),
            // 您的AccessKey Secret
            "accessKeySecret" => sysconfig('upload', 'alioss_access_key_secret'),
            'endpoint' => sysconfig('upload', 'alioss_clip_endpoint')//sysconfig('upload', 'alioss_clip_endpoint'),
        ]);
        $client = new ICE($config);
        $ClipSoundContentModel = new ClipSoundContent();
        $soundInfo = $ClipSoundContentModel->where(['id' => $param['id']])->find();
        $audioSmartHandleJobRequest = new GetSmartHandleJobRequest([
            "jobId" => $soundInfo['job_id']
        ]);
        $runtime = new RuntimeOptions([]);
        $audioSmartHandleJobResult = $client->getSmartHandleJobWithOptions($audioSmartHandleJobRequest, $runtime);
        if ($audioSmartHandleJobResult->body->state == 'Failed') {
            return result(-3, '失败' );
        }

        if ($audioSmartHandleJobResult->body->state == 'Finished') {
            $textArray = json_decode($audioSmartHandleJobResult->body->jobResult->aiResult);
            $SubtitleTrackClips = [];
            foreach ($textArray as $textValue) {

                $contentData['TimelineIn'] = $textValue->from;
                $contentData['TimelineOut'] = $textValue->to;
                $contentData['Content'] = $textValue->content;
                $SubtitleTrackClips[] = $contentData;
            }
            if ($SubtitleTrackClips) {
                $content = json_encode($SubtitleTrackClips);
                $ClipSoundContentModel->where(['id' => $param['id']])->update(['content' => $content]);
            }
            $info = $ClipSoundContentModel->where(['id' => $param['id']])->find();
            $info['content'] =  json_decode($info['content'] , true);

            return result(0, 'success', $info);
        }else{
            return result(-3, '重新请求' );
        }

    }


    public function deleteMission(){
        $request = $this->request;
        $param = $request->param();
        $clipMissionModel = new ClipMission();
        $info = $clipMissionModel->where(['id' => $param['id']])->find();
        $info->delete();
        return result(0, '删除成功');
    }


    public function  deleteProject(){
        $request = $this->request;
        $param = $request->param();
        $clipMissionModel = new ClipProject();
        $id = $param['id'];
        //$id = explode(',',$param['id']);
        $row = $clipMissionModel->whereIn('id', $id)->select();
        $save =$row->delete();
        return result(0, '删除成功');

    }

    public function moveProject(){
        $request = $this->request;
        $param = $request->param();
        $clipMissionModel = new ClipProject();
        $id = $param['id'];
        //$id = explode(',',$param['id']);
        $row = $clipMissionModel->whereIn('id', $id)->select()->toArray();

        $ScanTaskModel = new ScanTask();

        foreach ($row as  $value){
            $ScanTaskInfo  = $ScanTaskModel->where(['mission_id' =>$param['mission_id'],'select_type'=>1])->find();
            if ( $value['operation_text']){
                $clipMissionModel->where(['id' => $value['id']])
                    ->update(['mission_id' => $param['mission_id'],
                        'operation_text' =>
                            $value['operation_text'].'--'.'old_mission_id:'.$value['mission_id']]);
            }else{
                $clipMissionModel->where(['id' => $value['id']])
                    ->update(['mission_id' => $param['mission_id'],
                        'operation_text' =>'old_mission_id:'.$value['mission_id']]);
            }


            if($ScanTaskInfo){
                if ($ScanTaskInfo['select_type'] ==1){
                    $video['three_video_task_id'] = $value['id'];
                    $video['scan_task'] = $ScanTaskInfo['id'];
                    $video['create_time'] = time();
                    $scan_task_video  = new ScanTaskVideo();
                    $scan_task_video->save($video);
                    $ScanTaskModel->where(['id' =>$ScanTaskInfo['id']])->inc('video_num')->inc('surplus_num')->update();
                    $ClipProject = new ClipProject();
                    if ($ScanTaskInfo['channle_type'] == 1){
                        $ClipProject->where('id', $value['id'])->update(['is_douyin' => 2]);
                    }else{
                        $ClipProject->where('id', $value['id'])->update(['is_kuaishou' => 2]);
                    }
                }
            }

        }
        // $save =$row->delete();
        return result(0, '修改成功');
    }




//    public function updateConent()
//    {
//        $request = $this->request;
//        $param = $request->param();
//        $ClipSoundContentModel = new ClipSoundContent();
//        $info = $ClipSoundContentModel->where(['id' => $param['id']])->update(['keynote_content' =>$param['keynote_content'] ,'content'=>$param['content'] ]);
//        return result(1, 'success', $info);
//
//
//    }

}